package operation;

import Book.Book;
import Book.BookList;

import java.util.InputMismatchException;
import java.util.Scanner;

public class AddOperation implements Ioperation  {
    public void work(BookList bookList){
        System.out.println("新增图书");
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入你要新增图书的书名：");
        String name=scanner.nextLine();
        System.out.println("请输入你要新增图书的作者：");
        String author=scanner.nextLine();
        System.out.println("请输入你要新增图书的价格：");
        int price=scanner.nextInt();
        scanner.nextLine();
        System.out.println("请输入你要新增图书的类型：");
        String type=scanner.nextLine();
        Book book=new Book(name,author,price,type);
        int curcount=bookList.getUseSize();
        for (int i = 0; i < curcount; i++) {
            Book tem=bookList.getBook(i);
            if(tem.getName().equals(name)){
                System.out.println("存在这本书，不能重复添加");
                return;
            }
        }
        bookList.setBooks(book,curcount);
        bookList.setUseSize(curcount+1);
    }
}
